package com.cskaoyan.gateway.controller.shopping;

import com.cskaoyan.gateway.form.shopping.PageGoodsInfo;
import com.cskaoyan.gateway.form.shopping.PageResponse;
import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductRequest;
import com.mall.shopping.dto.AllProductResponse;
import com.mall.user.annotation.Anoymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: GoodsControllerTest
 * @Description:
 * @author: by zjl
 * @Date: 2021/5/22   14:24
 */

@Slf4j
@RestController
@RequestMapping("/shopping")
@Api(tags = "GoodsController", description = "商品控制层")
public class GoodsController {

    @Reference(timeout = 3000,retries = 0,check = false)
    IProductService iProductService;

    /**
     *
     * @param pageInfo
     * @return
     */
    @Anoymous
    @GetMapping("/goods")
    @ApiImplicitParam(name = "pageInfo", value = "分页信息", dataType = "PageInfo", required = true)
    public ResponseData goodsList(PageGoodsInfo pageInfo){
        //AllProductRequest
        AllProductRequest allProductRequest = new AllProductRequest();

        allProductRequest.setPage(pageInfo.getPage());
        allProductRequest.setCid(pageInfo.getCid());
        allProductRequest.setPriceGt(pageInfo.getPriceGt());
        allProductRequest.setPriceLte(pageInfo.getPriceLte());
        allProductRequest.setSort(pageInfo.getSort());
        allProductRequest.setSize(pageInfo.getSize());
        //AllProductResponse
        AllProductResponse response = iProductService.getAllProduct(allProductRequest);


        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())){  //000000

            //PageResponse:data,total
            PageResponse pageResponse = new PageResponse();
            pageResponse.setData(response.getProductDtoList());
            pageResponse.setTotal(response.getTotal());

            return new ResponseUtil<>().setData(pageResponse);
        }

        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

}